package com.biz.hunter.dao;


import java.util.Collections;
import java.util.Date;
import java.util.List;

import org.springframework.stereotype.Repository;
import com.biz.hunter.db.entity.SurveyPerson;
import com.biz.hunter.dbutil.BaseDAO;


@Repository
public class SurveyPersonDAO {
	protected static final String SQL_SAVE = "insert into tb_person_temp("
	    + "name, phone,email,service,"
	    + "otherservice, companyName,roleName,  location,"
	    + " baseSlry, award, totalSlry, lastPercent,"
	    + " expectPercent,projectName,expectCompany,expectCompany1, "
			+ "expectCompany2,expectCompany3) "
			+ "values(?,?,?,?"
			+ ",?,?,?,?"
			+ ",?,?,?,?"
			+ ",?,?,?,?"
			+ ",?,?)";

	
	protected static final String SQL_GET_ALL = "select * from tb_person_temp ";
	
	protected static final String SQL_GET_BY_PHONE = "select * from tb_person_temp where phone = ?";
	
	protected static final String SQL_GET_LIST = "select * from tb_person_temp where id in (?)";
	
	protected static final String SQL_GET_ID = "select * from tb_person  where id = ?";
	
	
  public int save(SurveyPerson person) {
    if (person == null) {
      return -1;
    }
    Long id = BaseDAO.save(SQL_SAVE, person.getName(), person.getPhone(), person.getEmail(), person.getService(), person.getOtherservice(), person.getCompanyName(),
                           person.getRoleName(), person.getLocation(), person.getBaseSlry(), person.getAward(), person.getTotalSlry(), person.getLastIncrease(),
                           person.getExpectIncrease(), person.getProjectName(), person.getExpectCompany(), person.getExpectCompany1(), person.getExpectCompany2(),
                           person.getExpectCompany3());
    if (id != null) {
      return id.intValue();
    }
    return -1;

  }

	

	public List<SurveyPerson> get(String... Ids) {
		if (Ids != null) {
			StringBuilder sql = new StringBuilder(SQL_GET_LIST);
			boolean start = false;
			for (String id : Ids) {
				if (start) {
					sql.append(",").append(id);
				} else {
					start = true;
					sql.append(id);
				}
			}
			sql.append(")");
			return BaseDAO.queryForList(SurveyPerson.class, sql.toString());

		} else {
			return Collections.emptyList();
		}
	}
	
	public List<SurveyPerson> getALL() {
		return BaseDAO.queryForList(SurveyPerson.class, SQL_GET_ALL);
	}
	

	
	

	public SurveyPerson getById(int personId) {
		return  BaseDAO.queryForObject(SurveyPerson.class, SQL_GET_ID, personId);
	}

	public SurveyPerson getByPhone(String phone) {
		return  BaseDAO.queryForObject(SurveyPerson.class, SQL_GET_BY_PHONE, phone);
	}

	

}
